package server;

/**
 * @author chenx
 * @date 2021/8/25-22:51
 */
public class HttpProtocolUtil {
    /**
     * 返回200 注意每行后面的换行符 "\n"
     * @param  contentLength 内容长度
     * @return 200
     */
    public static String getHttpHeader200(long contentLength){
        return "HTTP/1.1 200 OK \n"+
                "Content-Type: text/html \n"+
                "content-length: "+contentLength+" \n"+
                "\r\n";

    }

    /**
     * 返回404 注意每行后面的换行符 "\n"
     * @return 404
     */
    public static String getHttpHeader404(){
        String str404 = " <h1>404 Not Found ！</h1> ";
        return "HTTP/1.1 404 OK \n"+
                "Content-Type: text/html; charset=utf-8 \n"+
                "content-length: "+str404.getBytes().length+" \n"+
                "\r\n" + str404;
    }
}
